<template>
    <div>
        <div class="search-con search-con-top">
            <div>
                标题：
                <Input v-model="searchData.title" style="width: 200px"></Input>

                <Button @click="search" type="primary" icon="ios-search" style="margin-left: 10px;">搜索</Button>
                <Button @click="reset" type="warning" icon="ios-refresh" style="margin-left: 10px;">刷新</Button>
                <Button slot="extra" @click="edit(false)" type="success" style="margin-left: 10px;">添加</Button>
            </div>
        </div>
        <br>
        <Table :columns="columns" :data="list" :highlight-row="true" max-height="800" border stripe size="small">
            <template slot-scope="{ row , index}" slot="typeSlot">
                <!-- <div v-html="row.content"></div> -->
                {{ row.content }}
            </template>
            <template slot-scope="{ row , index}" slot="contextSlot">
                <div style="height: 200px;width: 100px;"><span v-html="row.context"></span></div>

            </template>
            <template slot-scope="{ row , index}" slot="makeSlot">
                <Button type="info" @click="edit(row)" size="small">编辑</Button>
                <Button type="error" @click="del(row.id)" size="small">删除</Button>
            </template>
        </Table>
        <br>

        <Paginate :total="total" @on-change="changePage" @on-page-size-change="changeSize" :current="searchData.page">
        </Paginate>


        <Drawer title="添加" :closable="false" width="80" v-model="showAdd">
            <Form ref="formValidate" :model="formItem" :label-width="100">
                <FormItem label="标题">
                    <Input v-model="formItem.title" placeholder=""></Input>
                </FormItem>
                <!-- <FormItem label="内容">
                    <RichText ref="ric" @getEditorContent="getRichTextContent" :content="formItem.content"></RichText>
                </FormItem> -->
                <FormItem>
                    <Button type="primary" @click="addQuestion()">提交</Button>
                </FormItem>
            </Form>
        </Drawer>
    </div>
</template>

<script>
import Paginate from "_c/paginate";
import RichText from "_c/rich-text"

export default {
    name: "report",
    components: {
        RichText, Paginate
    },
    data() {
        return {
            searchData: {
                page: 1,
                limit: 10
            },
            // 列表
            columns: [
                {
                    title: '标题',
                    key: 'title',
                    align: 'center',
                },
                // {
                //     title: '内容',
                //     key: 'type',
                //     align: 'center',
                //     tooltip:true,
                //     tooltipMaxWidth :400,
                //     slot: "typeSlot"
                // },
                {
                    title: '创建时间',
                    key: 'create_time',
                    align: 'center',
                },
                {
                    title: '操作',
                    slot: 'makeSlot',
                    align: 'center',
                },
            ],
            // 数据
            list: [],
            total: 0,
            formItem: {},
            showAdd: false,
        }
    },
    methods: {
        getRichTextContent(value) {
            this.formItem.content = value;
        },
        // 查询管理员信息
        getList() {
            this.$axios('/admin/verify/report/getList', this.searchData).then(res => {
                this.list = res.data;
                this.total = res.total;
            });
        },
        search() {
            this.searchData.page = 1;
            this.getList();
        },
        reset() {
            this.searchData = {
                page: 1,
                limit: 10,
            };
            this.getList();
        },
        changePage(page) {
            this.searchData.page = page;
            this.getList();
        },
        changeSize(size) {
            this.searchData.limit = size;
            this.getList();
        },
        customSort(column, key, order) {
            this.searchData.order_by = column.key;
            this.searchData.sort = column.order;
            this.getList();
        },
        addQuestion() {
            this.$axios('/admin/verify/report/save', this.formItem).then(res => {
                this.$Message.success('保存成功');
                this.formItem = {};
                this.showAdd = false;
                this.getList();
            });

        },
        edit(row) {
            if (row) {
                this.formItem.id = row.id;
                this.formItem.title = row.title + '';
                this.formItem.content = row.content;
            } else {
                this.formItem = {
                    id: 0,
                    title: '',
                    content: '',
                }
            }
            this.showAdd = true;
        },
        del(id) {
            this.$axios('/admin/verify/report/del', { id: id }).then(res => {
                this.$Message.success('删除成功');
                this.getList();
            });
        },

    },
    created() {
        this.getList();
    }
}
</script>
